<!--
  - $Id: logEventQuery.xhtml 21 2014-09-01 04:28:35Z ratking $
  -
  - Copyleft (C) 2014 RatKing. All wrongs reserved.
-->
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:f="http://xmlns.jcp.org/jsf/core"
                xmlns:h="http://xmlns.jcp.org/jsf/html"
                xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                template="/WEB-INF/layout/template.xhtml">

    <ui:define name="navigation">
        <p:breadCrumb>
            <p:menuitem value="首页" url="/index.xhtml"/>
            <p:menuitem value="系统管理" url="#"/>
            <p:menuitem value="日志管理" url="#"/>
        </p:breadCrumb>
    </ui:define>

    <ui:define name="helpInfo">
        <h:panelGrid>
            <h:outputText class="ui-icon icon-fugue-smiley" style="display: inline-block"/>
            日志事件查询与导出～<br/>
            帮助信息……
        </h:panelGrid>
    </ui:define>

    <ui:define name="content">
        <h:form id="logEventQueryForm">
            <p:fieldset legend="查询条件" toggleable="true">
                <h:panelGrid columns="4">
                    <h:panelGroup>
                        <p:outputLabel for="userId" value="用户ID："/>
                        <p:inputText id="userId"
                                     value="#{logEventSearchCriteria.userId}"
                                     size="10"
                                     title="请输入用户ID"/>
                    </h:panelGroup>

                    <h:panelGroup>
                        <p:outputLabel for="userName" value="用户名："/>
                        <p:inputText id="userName"
                                     value="#{logEventSearchCriteria.userName}"
                                     size="10"
                                     title="请输入用户名"/>
                    </h:panelGroup>

                    <h:panelGroup>
                        <p:outputLabel for="description" value="描述内容："/>
                        <p:inputText id="description"
                                     value="#{logEventSearchCriteria.description}"
                                     size="30"
                                     title="请输入描述内容"/>
                    </h:panelGroup>

                    <h:panelGroup>
                        <p:outputLabel value="创建日期："/>
                        <p:calendar value="#{logEventSearchCriteria.beginDate}"
                                    locale="zh_CN"
                                    navigator="true"
                                    pattern="yyyy-MM-dd"
                                    showButtonPanel="true"
                                    showWeek="true"
                                    size="10"/>
                        <h:outputText value="～"/>
                        <p:calendar value="#{logEventSearchCriteria.endDate}"
                                    locale="zh_CN"
                                    navigator="true"
                                    pattern="yyyy-MM-dd"
                                    showButtonPanel="true"
                                    showWeek="true"
                                    size="10"/>
                    </h:panelGroup>
                </h:panelGrid>
            </p:fieldset>

            <p:toolbar>
                <f:facet name="left">
                    <p:commandButton value="查询"
                                     action="#{logEventQuery.search}"
                                     icon="ui-icon-search"
                                     update="@form"/>

                    <span class="ui-separator">
                        <span class="ui-icon ui-icon-grip-dotted-vertical"/>
                    </span>

                    <p:commandButton value="批量删除"
                                     action="#{logEventQuery.batchDelete}"
                                     icon="ui-icon-close"
                                     onclick="if(!confirm('批量删除选中的日志记录吗？')){return false;}"
                                     update="@form"/>
                </f:facet>

                <f:facet name="right">
                    <p:commandButton value="导出Excel"
                                     icon="ui-icon-arrowreturnthick-1-n"
                                     ajax="false">
                        <p:dataExporter type="xls"
                                        target="resultTable"
                                        encoding="GBK"
                                        fileName="#{appResource.getFileName('系统日志', true)}"/>
                    </p:commandButton>
                </f:facet>
            </p:toolbar>

            <p:dataTable id="resultTable"
                         value="#{logEventQuery.resultModel}"
                         var="v_logEvent"
                         emptyMessage="找不到符合条件的日志事件"
                         lazy="true"
                         paginator="true"
                         paginatorPosition="both"
                         currentPageReportTemplate="查询到{totalRecords}条记录，本页显示{startRecord}～{endRecord}；第{currentPage}/{totalPages}页"
                         paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                         rows="20"
                         rowsPerPageLabel="每页行数"
                         rowsPerPageTemplate="5,10,20,50,100,200,500,1000"
                         rowIndexVar="rowIdx"
                         rowKey="#{v_logEvent.logEventId}"
                         selection="#{logEventQuery.selectedLogEvents}"
                         stickyHeader="true"
                         disabledTextSelection="false"
                         draggableColumns="true"
                         resizableColumns="true">
                         <!--stickyHeader="true"-->

                <p:column selectionMode="multiple"
                          styleClass="column-center"
                          exportable="false"/>

                <p:column styleClass="column-center">
                    <f:facet name="header">
                        <h:outputText value="序号"/>
                    </f:facet>
                    <h:outputText value="#{rowIdx+1}"/>
                </p:column>

                <p:column sortBy="#{v_logEvent.logEventId}" styleClass="column-center">
                    <f:facet name="header">
                        <h:outputText value="日志ID" title="logEventId"/>
                    </f:facet>
                    <h:outputText value="#{v_logEvent.logEventId}"/>
                </p:column>

                <p:column sortBy="#{v_logEvent.logType}" styleClass="column-center">
                    <f:facet name="header">
                        <h:outputText value="日志类型" title="logType(1-系统日志 2-安全日志 3-应用日志)"/>
                    </f:facet>
                    <h:outputText value="系统日志"
                                  title="#{v_logEvent.logType}"
                                  rendered="#{v_logEvent.logType == 1}"/>
                    <h:outputText value="安全日志"
                                  title="#{v_logEvent.logType}"
                                  rendered="#{v_logEvent.logType == 2}"/>
                    <h:outputText value="应用日志"
                                  title="#{v_logEvent.logType}"
                                  rendered="#{v_logEvent.logType == 3}"/>
                </p:column>

                <p:column sortBy="#{v_logEvent.logLevel}" styleClass="column-center">
                    <f:facet name="header">
                        <h:outputText value="日志级别" title="logLevel(1-信息 2-警告 3-错误)"/>
                    </f:facet>
                    <h:outputText value="信息"
                                  title="#{v_logEvent.logLevel}"
                                  styleClass="background-color:#ffffff"
                                  rendered="#{v_logEvent.logLevel == 1}"/>
                    <h:outputText value="警告"
                                  title="#{v_logEvent.logLevel}"
                                  styleClass="background-color:#ff9900"
                                  rendered="#{v_logEvent.logLevel == 2}"/>
                    <h:outputText value="错误"
                                  title="#{v_logEvent.logLevel}"
                                  styleClass="background-color:#ff0000"
                                  rendered="#{v_logEvent.logLevel == 3}"/>
                </p:column>

                <p:column sortBy="#{v_logEvent.eventSource}" styleClass="column-left">
                    <f:facet name="header">
                        <h:outputText value="操作来源" title="eventSource((模块名称、用户所访问的页面URL或产生事件的JavaBean名称))"/>
                    </f:facet>
                    <h:outputText value="#{v_logEvent.eventSource}"/>
                </p:column>

                <p:column sortBy="#{v_logEvent.userId}" styleClass="column-center">
                    <f:facet name="header">
                        <h:outputText value="用户ID" title="userId"/>
                    </f:facet>
                    <h:outputText value="#{v_logEvent.userId}"/>
                </p:column>

                <p:column sortBy="#{v_logEvent.userName}" styleClass="column-center">
                    <f:facet name="header">
                        <h:outputText value="用户名" title="userName"/>
                    </f:facet>
                    <h:outputText value="#{v_logEvent.userName}"/>
                </p:column>

                <p:column sortBy="description" styleClass="left-column">
                    <f:facet name="header">
                        <h:outputText value="描述信息" title="description"/>
                    </f:facet>
                    <h:outputText value="#{v_logEvent.description}"/>
                </p:column>

                <p:column sortBy="#{v_logEvent.clientIp}" styleClass="column-center">
                    <f:facet name="header">
                        <h:outputText value="操作IP" title="clientIp"/>
                    </f:facet>
                    <h:outputText value="#{v_logEvent.clientIp}"/>
                </p:column>

                <p:column sortBy="#{v_logEvent.createTime}" styleClass="column-center">
                    <f:facet name="header">
                        <h:outputText value="创建时间" title="createTime"/>
                    </f:facet>
                    <h:outputText value="#{v_logEvent.createTime}">
                        <f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss"/>
                    </h:outputText>
                </p:column>

                <p:column styleClass="column-center" exportable="false">
                    <f:facet name="header">操作</f:facet>
                    <p:commandLink title="查看"
                                   update=":display"
                                   oncomplete="PF('dlg').show()">
                        <h:outputText class="ui-icon ui-icon-zoomin" style="display: inline-block"/>
                        <f:setPropertyActionListener value="#{v_logEvent}" target="#{v_selectedLogEvent}"/>
                    </p:commandLink>
                    <p:spacer width="4"/>
                    <p:commandLink title="删除"
                                   action="#{logEventQuery.deleteById(v_logEvent.logEventId)}"
                                   update="@form"
                                   immediate="true"
                                   onclick="if (!confirm('删除日志事件“#{v_logEvent.logEventId}-#{v_logEvent.userName}”吗？')){return false;}">
                        <h:outputText class="ui-icon ui-icon-trash" style="display: inline-block"/>
                    </p:commandLink>
                </p:column>
            </p:dataTable>
        </h:form>

        <p:dialog id="display"
                  widgetVar="dlg"
                  draggable="true"
                  resizable="true"
                  closable="true"
                  minimizable="false"
                  maximizable="true"
                  modal="true"
                  position="center"
                  showEffect="explode"
                  hideEffect="explode"
                  appendTo="@(body)">

            <f:facet name="header">
                <h:outputText class="ui-icon ui-icon-person" style="display: inline-block"/>
                <h:outputText value="日志信息" title="Hi, RaTKiNG is here!"/>
            </f:facet>

            <p:panel>
                <h:panelGrid columns="4" columnClasses="grid-title,grid-normal,grid-title,grid-normal">
                    <h:outputText value="ID："/>
                    <h:outputText value="#{v_selectedLogEvent.logEventId}"/>

                    <h:outputText value="用户ID："/>
                    <h:outputText value="#{v_selectedLogEvent.userId}"/>

                    <h:outputText value="用户名："/>
                    <h:outputText value="#{v_selectedLogEvent.userName}"/>

                    <h:outputText value="描述信息："/>
                    <h:outputText value="#{v_selectedLogEvent.description}"/>

                    <h:outputText value="创建时间："/>
                    <h:outputText value="#{v_selectedLogEvent.createTime}">
                        <f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss"/>
                    </h:outputText>

                    <h:outputText value="操作机IP："/>
                    <h:outputText value="#{v_selectedLogEvent.clientIp}"/>
                </h:panelGrid>
            </p:panel>

            <f:facet name="footer">
                <div style="text-align: center">
                    <p:commandButton value="关闭"
                                     onclick="PF('dlg').hide()"
                                     icon="ui-icon-close"
                                     type="button"/>
                </div>
            </f:facet>
        </p:dialog>
    </ui:define>
</ui:composition>
